// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Data;
using JetBrains.Annotations;

namespace SnapObjects.Data.Oracle
{
    internal class OracleDecimalTypeMapping : OracleTypeMapping
    {
        public OracleDecimalTypeMapping(
            [NotNull] string dbTypeName,
            [CanBeNull] DbType? dbType = null)
            : base(dbTypeName, typeof(decimal), dbType)
        {
        }

        private const string DecimalFormatConst = "{0:0.0###########################}";

        /// <summary>
        ///     Creates a copy of this mapping.
        /// </summary>
        /// <param name="dbTypeName"> The name of the database type. </param>
        /// <param name="size"> The size of data the property is configured to store, or null if no size is configured. </param>
        /// <returns> The newly created mapping. </returns>
        public override TypeMapping Clone(string dbTypeName, int? size)
        {
            return new OracleDecimalTypeMapping(dbTypeName, this.DbType);
        }

        /// <summary>
        ///     Gets the string format to be used to generate SQL literals of this type.
        /// </summary>
        protected override string SqlLiteralFormatString => DecimalFormatConst;
    }
}
